package com.ewanghuiju.app.widget.popupwindow;

import android.content.Context;
import android.view.View;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.model.bean.response.PintuanOnlineListResponBean;
import com.ewanghuiju.app.ui.pintuan.adapter.AutoRollAdapter;
import com.ewanghuiju.app.widget.SmoothScrollLayoutManager;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import razerdp.basepopup.BasePopupWindow;

/**
 * @author sj  qq:751943509
 * @class 正在拼单 更多
 * @time 2020/2/19
 */
public class PintuanOlineMorePopup extends BasePopupWindow {


    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;

    private AutoRollAdapter mAdapter;

    private Context mContext;

    public PintuanOlineMorePopup(Context context) {
        super(context);
        this.mContext = context;
        ButterKnife.bind(this, getContentView());
    }

    public void setmRecyclerView(List<PintuanOnlineListResponBean> list) {
        if (mAdapter != null) {
            mAdapter.onDestroy();
        }
        mAdapter = new AutoRollAdapter(list, mContext, 1);
        SmoothScrollLayoutManager linearLayoutManager = new SmoothScrollLayoutManager(mContext);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setAdapter(mAdapter);

//        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
//        adapter = new PintuanPopupOnlineListAdapter(R.layout.item_pintuan_popup_online_list);
//        mRecyclerView.setAdapter(adapter);
//        adapter.addData(list);
//        adapter.notifyDataSetChanged();
    }

    @Override
    public View onCreateContentView() {
        return createPopupById(R.layout.popup_pintuan_online_more);
    }

    @Override
    public void onDismiss() {
        super.onDismiss();
        if (mAdapter != null) {
            mAdapter.onDestroy();
        }
    }

    @OnClick({R.id.popup_close})
    public void doClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.popup_close:
                dismiss();
                break;
            default:
                break;
        }
    }
}
